package com.miracle.db;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Test;

import com.miracle.cache.Channel;
public class TestDBConnection {


	//	@Ignore("db is down")
	@Test(timeout = 1010)
	public void testDBConnection() {
		long start = System.currentTimeMillis();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			conn = DBPool.getInstance().getConnection("tdlive");
			assertNotNull(conn);
			pstmt = conn.prepareStatement("select * from channel limit 1");
			rs = pstmt.executeQuery();
			Channel ch = new Channel();
			while (rs.next()) {
				ch.setId(rs.getInt(1));
				ch.setChannelName(rs.getString(2));
			}
			assertEquals("mini 13", ch.getChannelName());
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBPool.close(pstmt, rs, conn);
		}
	}

}
